package com.service;

//import com.baomidou.dynamic.datasource.annotation.DS;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.StudentDAO;
import com.dao.TeacherDAO;
import com.pojo.Student;
import com.pojo.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

@Service
public class StudentService extends ServiceImpl<StudentDAO, Student> {

    @Autowired
    private StudentDAO studentDAO;

    @Autowired
    private TeacherDAO teacherDAO;




    @Autowired
    public JdbcTemplate jdbcTemplate;



   @DSTransactional
    public void add() throws SQLException {

            addStudent();

             jdbcTemplate.update("insert into teacher(tname) values('111')");

            addTeacher();





    }




    public void addStudent() throws SQLException {
        Student stu = new Student();
        stu.setName("bbb");
        studentDAO.insert(stu);
        //throw new SQLException();
        //int i = 1/0;
    }


    //@DS("master")
    public void addTeacher() throws SQLException {
        Teacher teacher = new Teacher();
        teacher.setTname("ccc");
        teacherDAO.insert(teacher);



        throw new SQLException();
    }

}
